package com.controller;

import com.serivice.BookService;
import com.serivice.CategoryService;
import com.vo.R;
import com.vo.po.Book;
import com.vo.po.Category;
import com.vo.req.BookQueryDTO;
import com.vo.resp.BookQueryVO;
import com.vo.resp.CategoryVO;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/book")
@RequiredArgsConstructor
public class BookController {

    private final CategoryService categoryService;

    private final BookService bookService;

    /**
     * 获得图书分类
     * @return
     */
    @GetMapping("/bookCategory")
    public R<List<Category>> bookCategory(){
        return categoryService.bookCategory();
    }

    /**
     * 删除图书分类
     * @param id
     */
    @DeleteMapping("/bookCategory/{id}")
    public R delCategory(@PathVariable Integer id){
        return categoryService.delCategory(id);
    }

    /**
     * 新增分类
     * @param category
     */
    @PostMapping("/bookCategory")
    public R addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    /**
     * 修改分类
     * @param category
     */
    @PutMapping("/bookCategory")
    public R updateCategory(@RequestBody  Category category){
        return categoryService.updateCategory(category);
    }

    /**
     * 根据条件分页查询
     * @param queryDTO
     * @return
     */
    @GetMapping("/list")
    public R<BookQueryVO> listByCondition( BookQueryDTO queryDTO){
        return bookService.listByCondition(queryDTO);
    }

    /**
     * 删除图书
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R deleteBook(@PathVariable Integer id){
        return bookService.deleteBook(id);
    }

    /**
     * 新增图书
     * @param book
     * @return
     */
    @PostMapping
    public R addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }

    /**
     * 修改图书
     * @param book
     * @return
     */
    @PutMapping
    public R updateBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }

    /**
     * 图书分类统计
     * @return
     */
    @GetMapping("/chart/category")
    public R<List<CategoryVO>> g(){
        return bookService.getCategoryData();
    }


    /**
     * 图书价格统计
     * @return
     */
    @GetMapping("/chart/price")
    public R<List<Integer>> getPriceData(){
        return bookService.getPriceData();
    }



}